﻿using Blog.Core.Domain.Model.User;
using Blog.Core.DTO.ViewModel.User;
using Blog.Core.DTO;
using Blog.Core.IServices;
using Blog.Core.IServices.IUser;
using Blog.Core.Services.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Blog.Core.Api.Controllers
{
    /// <summary>
    /// 部门控制器
    /// </summary>
    [Authorize]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepartmentInfoController : BaseController<DepartmentInfo>
    {
        private readonly IDepartmentInfoService _departmentInfoService;
		/// <summary>
		/// 部门控制器，增删改查
		/// </summary>
		/// <param name="baseService"></param>
		/// <param name="departmentInfoService"></param>
		public DepartmentInfoController(IBaseService<DepartmentInfo> baseService,IDepartmentInfoService departmentInfoService) : base(baseService)
        {
            _departmentInfoService = departmentInfoService;
        }
        /// <summary>
        /// 部门树形显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
		[AllowAnonymous]
		public async Task<IActionResult> DepartmentShow(int id=0)
        {
			ResponseResultDTO<List<DepartmentInfoDTO>> Dep = new ResponseResultDTO<List<DepartmentInfoDTO>>();
            Dep.Code = ResultStatusCode.SUCCESS;
            Dep.Message = "成功";
            Dep.Data=await _departmentInfoService.DepartmentList(id);
            return Ok(Dep);
		}


        /// <summary>
        /// 部门用户显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
		[AllowAnonymous]
		public async Task<IActionResult> DepartmentFind(int? id)
        {
            return Ok(await _departmentInfoService.DepartmentUser(id));
        }

		/// <summary>
		/// 添加部门
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		[AllowAnonymous]
		public async Task<IActionResult> DepartmentAdd(DepartmentInfo dto)
        {
            return Ok(await _departmentInfoService.DepartmentInfoAdd(dto));
        }
        
	}


}
